<template>
  <div class="carousel-container">
    <button class="arrow left-arrow" @click="prevImages" :disabled="currentIndex <= 0">‹</button>
    <div class="carousel-wrapper">
      <div class="carousel-track" :style="{ transform: `translateX(-${currentIndex * (100 / 6)}%)` }">
        <div
          class="carousel-item"
          v-for="(image, index) in images"
          :key="index"
        >
          <img :src="image.url" alt="carousel image" />
        </div>
      </div>
    </div>
    <button class="arrow right-arrow" @click="nextImages" :disabled="currentIndex + 6 >= images.length">›</button>
  </div>
</template>

<script>
export default {
  props: {
    images: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    nextImages() {
      if (this.currentIndex + 6 < this.images.length) {
        this.currentIndex += 1;
      }
    },
    prevImages() {
      if (this.currentIndex > 0) {
        this.currentIndex -= 1;
      }
    },
  },
};
</script>

<style scoped>
.carousel-container {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%; /* Adjust to fit your layout */
  max-width: 1200px; /* Optional max-width */
  margin: 0 auto;
}

.carousel-wrapper {
  overflow: hidden;
  width: 100%;
  position: relative;
}

.carousel-track {
  display: flex;
  transition: transform 0.3s ease;
}

.carousel-item {
  flex: 0 0 calc(100% / 6); /* 6 images per row */
  box-sizing: border-box;
}

.carousel-item img {
  width: 100%;
  display: block;
}

.arrow {
  background-color: rgba(0, 0, 0, 0.5);
  border: none;
  color: white;
  padding: 10px;
  cursor: pointer;
  font-size: 24px;
  user-select: none;
  z-index: 1;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.arrow:disabled {
  background-color: rgba(0, 0, 0, 0.2);
  cursor: not-allowed;
}

.left-arrow {
  left: 10px;
}

.right-arrow {
  right: 10px;
}
</style>
